package nc.tb.schema.ui;

import java.util.Comparator;
import javax.swing.JDialog;
import nc.tb.consolidate.IConsolidateUiConst;
import nc.tb.ctl.SheetModelCTL;
import nc.tb.ctl.StyleSheetCTL;
import nc.tb.cube.model.MetaPlan;
import nc.tb.dim.DimMember;
import nc.tb.dim.data.DimManager;
import nc.tb.pub.IDimPkConst;
import nc.tb.pub.tree.TbFCTreeModel;
import nc.tb.pub.tree.TbTreeNode;
import nc.tb.pub.ui.TbAutoMatchTreeDlg;
import nc.tb.pub.util.NtbLogger;
import nc.tb.pub.util.SortTool;
import nc.vo.pub.BusinessException;

public class ImpPlanDlg  {
	public static TbFCTreeModel getCubeTreeModel() {
		TbTreeNode root = new TbTreeNode(IConsolidateUiConst.STR_CUBE);
		try {
			DimMember[] dms = DimManager.getDimMembers(DimManager.getDimDefByPK(IDimPkConst.DEF_CUBECLASS));
			SortTool.sort(dms, new Comparator<DimMember>() {
				public int compare(DimMember dm1, DimMember dm2) {
					int i1 = 0, i2 = 0;
					try {
						i1 = Integer.parseInt(dm1.getObjcode());
					}
					catch (Exception e) {}
					try {
						i2 = Integer.parseInt(dm2.getObjcode());
					}
					catch (Exception e) {}
					return i1 - i2;
				}
			});
			TbFCTreeModel treeModel = new TbFCTreeModel(root, dms);
			root.setCanBeSelected(false);
			treeModel.setEnableTreeNodes(dms, false);
			MetaPlan[] cubes = StyleSheetCTL.getCubeByCondition(" issystem is null or issystem='N'");
			if (cubes != null) {
				for (int i=0; i<cubes.length; i++) {
					treeModel.addBusiObjByParent(cubes[i], cubes[i].getCubeInfo().getPk_cubeindex());
				}
			}
			return treeModel;
		} catch (BusinessException e) {
			NtbLogger.printException(e);
			return new TbFCTreeModel(root, null);
		}
	}
	
}
